class Particle
{
  PVector pos;
  PVector vel;
  float posZ = 0;
  float siz;
  float life, lifeMax;  
  color col;

  Particle(PVector pos, float vel, float siz, color col)
  {
    this.pos = pos;
    this.vel = new PVector(0,0,vel);
    this.siz = siz;
    this.col = col;
    life = random(0.05, 0.1);
    lifeMax = life;
  }

  void update()
  {
    //pos.sub(vel);
    //pos.z -= 0.001f;
    vel.mult(0.5f);
    //siz *= 0.95f;
    life -= 0.016666667f;
  }

  void render()
  {    
    // Render setting

    // Render
    pushMatrix();

    float factor = 500;

    translate(pos.x*factor, pos.y*factor, factor-pos.z*factor);

    stroke(col,255-getAge()*255);
    noFill();
    line(0,0,0,0,0,vel.z);

    translate(0,0,vel.z);

    //noStroke();
    //fill(col,255-getAge()*255);
    box(siz,siz,siz);

    popMatrix();
  }

  // Get normalized an age of the particle
  float getAge()
  {
    float age = map(life, 0.0, lifeMax, 0.0, 1.0);
    return constrain(age,0.0,1.0);
  }
}

